package com.atguigu.test.mvc.editor;

import java.beans.PropertyEditorSupport;

/**
 * @author zp
 * @version 1.0
 * @description: 自定义属性编辑器 把字符串当中的{、} 变成{{、}}
 * @date 2023/1/13 19:44
 */
public class MyStringEditor extends PropertyEditorSupport {

    @Override
    public boolean isPaintable() {
        return super.isPaintable();
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if(text == null){
            setValue(null);
        }else {
            text = text.replace("{","{{");
            text = text.replace("}","}}");
            setValue(text);
        }
    }

    @Override
    public String getAsText() {
        Object value = getValue();
        return (value != null ? value.toString() : "");
    }
}
